﻿using SaaS.Model.Dto.Sites;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using XCore.Domain.Data;
using XCore.Domain.Entities;

namespace SaaS.Model.Entity.Sites
{
    /// <summary>
    /// 站点租户表
    /// </summary>
    [Table("Sites")]
    public class Site : IEntity<int>, IHasCreationTime
    {
        [Column("SiteId")]
        public int Id { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        [StringLength(32)]
        [Required]
        public string Name { get; set; }
        /// <summary>
        /// 秘钥
        /// </summary>
        [Required]
        [StringLength(64)]
        public string SecretKey { get; set; }
        /// <summary>
        /// 域名前缀
        /// </summary>
        [StringLength(32)]
        public string Domain { get; set; }
        /// <summary>
        /// 是否宿主（配置数据库）
        /// </summary>
        public bool IsHost { get; set; }
        /// <summary>
        /// 链接字符串
        /// </summary>
        [StringLength(256)]
        public string ConnectionString { get; set; }
        /// <summary>
        /// 数据库类型
        /// </summary>
        public DatabaseType? Type { get; set; }
        public DateTime CreationTime { get; set; }
        public string IP { get; set; }

        public static implicit operator SiteModel(Site site)
        {
            return new SiteModel()
            {
                SiteId = site.Id,
                ConnectionString = site.ConnectionString,
                Domain = site.Domain,
                IsHost = site.IsHost,
                Name = site.Name,
                SecretKey = site.SecretKey,
                Type = site.Type
            };
        }

    }
}
